﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using Shanfree.Framework.Utility;
using Shanfree.SharpMovie.BLL;
using Shanfree.SharpMovie.Model;
using System.Web.UI.WebControls;

public partial class List_List : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindList(pGrid.CurrentPageIndex);
        }
    }

    #region 列表控件事件
    /// <summary>
    /// 翻页
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void pGrid_OnClick(object sender, EventArgs e)
    {
        try
        {
            BindList(pGrid.CurrentPageIndex);
        }
        catch (Exception exc)
        {
            ShowMsg(exc.Message);
            LogEntry.Log.Write(exc.ToString(), EventLogEntryType.Error, LogSourceType.一般错误);
        }
    }

    private void BindList(int p)
    {
        IList<ListInfo> list = new List().GetList(this.CurrentUser.ID,gvList.PageSize, pGrid.CurrentPageIndex);
        CustomList<ListInfo> cList = list as CustomList<ListInfo>;
        if (gvList.PageSize * pGrid.CurrentPageIndex >= cList.TotalAmout)
        {
            pGrid.CurPageNumber--;
            list = new List().GetList(gvList.PageSize, pGrid.CurrentPageIndex);
        }
        gvList.DataSource = list;
        gvList.DataBind();
        if (null != cList)
        {
            pGrid.PageSize = gvList.PageSize;
            pGrid.TotalAmout = cList.TotalAmout;
        }
    }
    #endregion

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        Response.Redirect("Add.aspx", false);
    }
    protected void btnTranAdd_Click(object sender, EventArgs e)
    {
        Response.Redirect("TranImport.aspx", false);
    }
    protected void btnDel_Click(object sender, EventArgs e)
    {
        try
        {
            string id = lbID.Value;
            Response.Write(id);
            BindList(pGrid.CurrentPageIndex);
            ShowMsg("该收藏分类已删除。");
            //new List().Delete(id);
        }
        catch (Exception exc)
        {
            ShowMsg(exc.Message);
            LogEntry.Log.Write(exc.ToString(), EventLogEntryType.Error, LogSourceType.一般错误);
        }
    }
    protected void gvList_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            ListInfo lInfo = e.Row.DataItem as ListInfo;
            // 选择控件，传入收件的事务主键，用来更新
            RadioButton rbSel = (RadioButton)e.Row.FindControl("rbSel");
            rbSel.Attributes.Add("onclick", "Sel('" + lInfo.ID + "')");
        }

    }
}
